<?php
date_default_timezone_set('Asia/ShangHai');
error_reporting(E_ALL & ~E_NOTICE);
$charset = 'utf-8';
//$charset = 'gb-2312';
//$charset = 'gbk';
header('Content-Type:text/html; charset='.$charset);

require_once 'classes/data.class.php';
require_once 'classes/content_clip.class.php';

require_once 'inc/function.php';

require_once 'classes/upyun.class.php';

$a = 'asdfuread.melkj';
preg_match('/uread\.me/i', $a, $match);
pre_echo($match);
?>



<?php

die();


/* 另外：	60	腾讯的页面上采集不到内容？？？？
 * 
 * 
 * 有问题的id
 *		21	知乎的论坛类型，需要另外一种模式来匹配了	14%	txt:3187
 *		24	虎嗅的正文中有太多div，每一个都不大，这里big center只有5%的长度
 *		43	百度百科，太多小div组成的，好像得用另外一种模式来匹配
 *		45	同上
 *		47	是用table写的，考虑split的时候增加table的分割，或者tr的分割？tr可能会太小了
 *		50	也是论坛模式吗？
 *		61, 66，123,138,139,140
 *		143
 * 
 * 
 *		57,194	论坛，获取图片尺寸超时
 *		108	错了，把正文丢了，广告抓进来了
 * 
 *		118	后面的代码丢了
 *		121,124	前面丢了一部分
  *		131	前面多了，后面丢了，没有办法
 *		132	后面丢了一部分
 *		135,136	前面的代码丢了一部分
 * 
 *		146	电商列表
 *		147	分散模式
 *		149	homepage
 *		150,159
 *		182,183,184,186,188,198,199
 *	
 *		179 
 * 
 *		200 中间怎么有textarea??!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 *		217,221
 *		
 * 
 *		
 */

class test {
	public $id;
	public $next_id;
	private $filename;
	public $url;
	public $content;
	
	public function __construct() {
		$id = intval($_GET['id']);
		if ($id) {
			$this->id = $id;
			$this->filename = 'html/' . $id . '.html';
			
			mysql_connect('localhost', 'root', '123456');
			mysql_query('SET NAMES UTF8');
			mysql_select_db('ureadmev07');

			$query = mysql_query('
				select 
					save_article.id, 
					article_url.url,
					save_article_content.content
				from 
					save_article, 
					article_url,
					save_article_content
				where 
					save_article.id		> "'.$this->id.'"		and 
					article_url.id		= save_article.url_id	and
					save_article_content.id	= save_article.id
				limit 1
			');
			$fetch = mysql_fetch_assoc($query);
			
			$this->next_id = $fetch['id'];
			
			$this->url = $fetch['url'];
			if (!file_exists($this->filename)) {
				// step 1
				$ob = new content_clip();
				$this->save_content($ob->replace_for_save($fetch['url'], $fetch['content']));
			}
			
			$this->get_content();
		} else die('-- No Id --');
	}
	public function save_content ($content) {
		$fp = fopen($this->filename, 'w');
		fwrite($fp, $content);
		fclose($fp);
	}
	public function get_content () {
		$this->content = file_get_contents($this->filename);
		return $this->content;
	}
}

$test = new test();


	if ($_GET['type'] == 'content') {
		echo $test->content;
	} elseif ($_GET['type'] == 'analyze') {
		$ob = new content_clip();
		
		// step 2
		$new_content = $ob->download_big_img_and_replace($test->get_content());
		if ($new_content) {
			pre_echo('have new download to replace');
			$test->save_content($new_content);
		}
		// 3
		$analyse = $ob->analyse($test->get_content(), $test->url);
		
		if ($analyse['summary']) {
			echo '
				<div style="height:80px; width:470px; padding:10px; border:1px solid blue; background-color:#EEE; font-size:14px; line-height:150%; font-family:微软雅黑;">
					'.(($analyse['big_imgs'][0]) ? '<img src="'.$analyse['big_imgs'][0].'" style="width:140px; height:80px; margin:0 10px 10px 0; border:1px solid #CCC; " align=left >' : '').'
					'.$analyse['summary'].'
				</div>
			' ;
		} elseif ($analyse['big_imgs']) {
			echo '<div style="height:80px; width:470px; padding:10px; border:1px solid blue; background-color:#EEE; font-size:14px; line-height:150%; font-family:微软雅黑; word-break:break-all;word-wrap:break-word;">';
			foreach ($analyse['big_imgs'] as $k=>$src) {
				echo '<img src="'.$src.'" style="width:140px; height:80px; margin:1px; border:1px solid #CCC; ">';
			}
			echo '</div>' ;
		}
		if ($analyse['clip']) {
			echo '<div style="width:500px;">'.$analyse['clip'].'</div>';
		} else {
			echo '<div style="padding:5px; background-color:#000; color:#FFF; clear:both; float:none;">Can not create clip</div>';
		}
//		echo '<br><br>--------------------------------------------------------------------------------------------------------------<br><br>';
		echo $ob->display();
	} elseif ($_GET['id']) {
		echo '
		<div style="background-color:#EEE; padding:10px;">
			<a href="/test.php?id='.$test->next_id.'">Next</a>
			|
			<a href="'.$test->url.'" target="_blank">'.$test->url.'</a>
		</div>
		<table width=100%>
			<tr valign=top>
				<td width=700><iframe src="/test.php?type=content&id='.$test->id.'" width=700 height=700></iframe></td>
				<td width=700><iframe src="/test.php?type=analyze&id='.$test->id.'" width=700 height=700></iframe></td>
			</tr>
		</table>
		';
	}
?>